﻿using System;
using System.Collections.Generic;
using System.Management;
using System.Linq;
using System.Text;

namespace WMI_Printer
{
    class Program
    {
        static void Main(string[] args)
        {
            ConnectionOptions objconn = new ConnectionOptions();
            objconn.Impersonation = ImpersonationLevel.Impersonate;
            objconn.EnablePrivileges = true;
            objconn.Username = @"d1\sraimondi";
            objconn.Password = "Stefo78336";
            string servername = "sobde0e1";
            ManagementScope printerscope = new ManagementScope(@"\\" + servername + @"\root\cimv2", objconn);
            ObjectQuery printerquery = new ObjectQuery("SELECT * FROM Win32_Printer");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(printerscope, printerquery);
            int i = 0;
            foreach (ManagementObject objwmi in searcher.Get())
            {
                i++;
                Console.WriteLine("************ Printer ******* n"+i);
                PropertyDataCollection searcherproperties = objwmi.Properties;
                foreach (PropertyData pd in searcherproperties)
                {
                    Console.WriteLine(pd.Name + " : " + pd.Value);
                }
            }
            Console.ReadKey();
        }
    }
}
